package com.nursing.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nursing.Dao.CarePlanDao;
import com.nursing.bean.CarePlan;
import com.nursing.model.dto.CarePlanDto;
import com.nursing.model.dto.CareTaskDto;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PlanService {
    private final CarePlanDao carePlanDao;

    public PlanService(CarePlanDao carePlanDao) {
        this.carePlanDao = carePlanDao;
    }

    public void addPlan(CarePlan carePlan) {
        carePlan.setCreatedAt(LocalDateTime.now());
        carePlan.setStatus(0); // 初始化设置为未分配
        carePlanDao.insert(carePlan);
    }

    public void deletePlan(Integer id) {
        carePlanDao.delete(id);
    }

    public void updatePlan(CarePlan carePlan) {
        carePlanDao.update(carePlan);
    }

    public PageInfo<CarePlanDto> list(int page, int size) {
        PageHelper.startPage(page, size);
        List<CarePlanDto> carePlans = carePlanDao.getAll();
        return new PageInfo<>(carePlans);
    }

    public CarePlan getPlanById(Integer id) {
        return carePlanDao.getById(id);
    }
}
